<template>
    <div class="personal layout-pd">
        <el-row>
            <!-- 个人信息 -->
            <el-col :xs="24" :sm="24">
                <el-card shadow="never">
                    <template #header>
                        <div class="card-header">
                            <el-icon :size="20">
                                <importr />
                            </el-icon>个人信息
                        </div>
                    </template>
                    <div class="personal-importr">
                        <div class="personal-importr-left">
                            <UploadImage v-model="importrInfo.txdz" :width="100" :height="130" />
                        </div>
                        <div class="personal-importr-right">
                            <el-row>
                                <el-col :span="24" class="personal-title mb18">
                                    <el-descriptions class="margin-top" :title="`${currentTime}，欢迎使用松桃警务助手平台！`" :column="4"
                                        border>
                                        <template #extra>
                                            <el-button type="primary" :icon="Edit"
                                                @click="formDialogRef!.acceptParams()">修改密码</el-button>

                                                <el-button type="success" :icon="Plus"
                                                @click="opinionDialogRef!.acceptParams()">我要反馈</el-button>
                                        </template>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <importr />
                                                    </el-icon>
                                                    姓名
                                                </div>
                                            </template>
                                            {{ importrInfo.xm }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <importr />
                                                    </el-icon>
                                                    登录名
                                                </div>
                                            </template>
                                            {{ importrInfo.dlm }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <iphone />
                                                    </el-icon>
                                                    联系方式
                                                </div>
                                            </template>
                                            {{ importrInfo.lxfs }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <Message />
                                                    </el-icon>
                                                    邮箱
                                                </div>
                                            </template>
                                            {{ importrInfo.yx }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <Postcard />
                                                    </el-icon>
                                                    证据号码
                                                </div>
                                            </template>
                                            {{ importrInfo.zjhm }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <Tickets />
                                                    </el-icon>
                                                    部门名称
                                                </div>
                                            </template>
                                            {{ importrInfo.bmmc }}
                                        </el-descriptions-item>
                                        <el-descriptions-item>
                                            <template #label>
                                                <div class="cell-item">
                                                    <el-icon>
                                                        <location />
                                                    </el-icon>
                                                    居住地址
                                                </div>
                                            </template>
                                            {{ importrInfo.jzdz }}
                                        </el-descriptions-item>
                                    </el-descriptions>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                </el-card>
            </el-col>
            <!-- 更新信息 -->
            <el-col :span="24">
                <el-card shadow="never" class="mt15 personal-edit" header="更新信息">
                    <div class="personal-edit-title">基本信息</div>
                    <el-form ref="ruleFormRef" :rules="rules" :model="formData" size="default" label-width="100px"
                        class="mt35 mb35">
                        <el-row :gutter="35">
                            <el-col :md="6" class="mb20">
                                <el-form-item label="姓名" prop="xm">
                                    <el-input v-model="formData.xm" placeholder="请输入姓名" clearable></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :md="6" class="mb20">
                                <el-form-item label="邮箱" prop="yx">
                                    <el-input v-model="formData.yx" placeholder="请输入邮箱" clearable></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :md="6" class="mb20">
                                <el-form-item label="手机" prop="lxfs">
                                    <el-input v-model="formData.lxfs" placeholder="请输入手机" clearable></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :md="6" class="mb20">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.xb" placeholder="请选择性别" clearable class="w100">
                                        <el-option label="男" value="男"></el-option>
                                        <el-option label="女" value="女"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :md="6">
                                <el-form-item>
                                    <el-button type="primary" @click="handleSubmit">
                                        <el-icon>
                                            <ele-Position />
                                        </el-icon>
                                        更新个人信息
                                    </el-button>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <!-- <div class="personal-edit-title mb15">账号安全</div>
                    <div class="personal-edit-safe-box">
                        <div class="personal-edit-safe-item">
                            <div class="personal-edit-safe-item-left">
                                <div class="personal-edit-safe-item-left-label">绑定手机 <el-tag
                                        v-if="importrInfo.lxfsYz == 1">已验证</el-tag><el-tag v-else type="error">未验证</el-tag>
                                </div>
                                <div class="personal-edit-safe-item-left-value">
                                    已绑定手机：{{ importrInfo.lxfs }}</div>
                            </div>
                            <div class="personal-edit-safe-item-right">
                                <el-button text type="primary">立即修改</el-button>
                            </div>
                        </div>
                    </div>
                    <div class="personal-edit-safe-box">
                        <div class="personal-edit-safe-item">
                            <div class="personal-edit-safe-item-left">
                                <div class="personal-edit-safe-item-left-label">绑定邮箱 <el-tag
                                        v-if="importrInfo.yxYz == 1">已验证</el-tag><el-tag v-else type="error">未验证</el-tag></div>
                                <div class="personal-edit-safe-item-left-value">已绑定QQ：110****566</div>
                            </div>
                            <div class="personal-edit-safe-item-right">
                                <el-button text type="primary">立即设置</el-button>
                            </div>
                        </div>
                    </div> -->
                </el-card>
            </el-col>
        </el-row>
        <OpinionDialog ref="opinionDialogRef" />
        <FormDialog ref="formDialogRef" />
    </div>
</template>
  
<script setup lang="ts" name="personal">
import { ref, reactive, computed, onMounted } from 'vue';
import rulesObj from './rules';
import {
    Iphone,
    Location,
    Tickets,
    Postcard,
    Edit,
    Message,
    Plus,
    importr,
} from '@element-plus/icons-vue'
import { formatAxis } from '/@/utils/formatTime';
import UploadImage from '/@/components/UploadImage/index.vue'
import FormDialog from './components/FormDialog.vue';
import OpinionDialog from './components/OpinionDialog.vue';
import { ElMessage, ElMessageBox, FormInstance } from "element-plus";
import { editimportr } from "/@/api/auth/importr";
import request from '/@/utils/request';
import { importHandleData } from '/@/hooks/importHandleData';
const formData = reactive<any>({
    id: '',
    xm: '',
    lxfs: '',
    yx: '',
    xb: '',
});

const importrInfo = ref<any>({
    xm: '',
    dlm: '',
    bm: '',
    zjlx: '',
    zjhm: '',
    lxfs: '',
    yx: '',
    bmmc: '',
    txdz: '',
    jzdz: '',
    lxfsYz: 0,
    yxYz: 0
})
const rules = reactive<any>(rulesObj)
const formDialogRef = ref(), opinionDialogRef = ref();

// 当前时间提示语
const currentTime = computed(() => {
    return formatAxis(new Date());
});
onMounted(async () => {
    const res = await request({ url: '/stjwzs/smimportr/getimportrInfo', method: 'get' });
    if (res && res.code === 0) {
        var data = res.data
        for (let key in importrInfo.value) {
            importrInfo.value[key] = data[key]
        }
        for (let key in formData) {
            formData[key] = data[key]
        }
        importrInfo.value.jzdz = res.extend.dz;
    }
});
const ruleFormRef = ref<FormInstance>();

const handleSubmit = () => {
    ruleFormRef.value!.validate((valid) => {
        if (!valid) return;

        let submitData = {}//需要提交的表单
        for (let key in formData) {
            if (formData[key] != importrInfo.value[key]) {
                submitData[key] = formData[key]
            }
        }
        if (Object.keys(submitData).length === 0) {
            ElMessage.error('您未做任何修改');
            return;
        }
        importHandleData(edit, { ...submitData, id: formData.id }, '更新个人信息');
    });
}


</script>
  
<style scoped lang="scss">
@import '../../theme/mixins/index.scss';

.personal {
    .card-header {
        display: flex;
    }

    .personal-importr {
        display: flex;
        width: 100%;
        align-items: center;

        .personal-importr-left {
            width: 100px;
            height: 130px;
            border-radius: 3px;

            :deep(.el-upload) {
                height: 100%;
            }

            .personal-importr-left-upload {
                img {
                    width: 100%;
                    height: 100%;
                    border-radius: 3px;
                }

                &:hover {
                    img {
                        animation: logoAnimation 0.3s ease-in-out;
                    }
                }
            }
        }

        .personal-importr-right {
            flex: 1 1 auto;
            width: 0;
            padding: 0 15px;

            .personal-title {
                font-size: 18px;
                @include text-ellipsis(1);
            }

            .personal-item {
                display: flex;
                align-items: center;
                font-size: 13px;

                .personal-item-label {
                    color: var(--el-text-color-secondary);
                    @include text-ellipsis(1);
                }

                .personal-item-value {
                    @include text-ellipsis(1);
                }
            }
        }
    }

    .personal-info {
        .personal-info-more {
            float: right;
            color: var(--el-text-color-secondary);
            font-size: 13px;

            &:hover {
                color: var(--el-color-primary);
                cursor: pointer;
            }
        }

        .personal-info-box {
            height: 130px;
            overflow: hidden;

            .personal-info-ul {
                list-style: none;

                .personal-info-li {
                    font-size: 13px;
                    padding-bottom: 10px;

                    .personal-info-li-title {
                        display: inline-block;
                        @include text-ellipsis(1);
                        color: var(--el-text-color-secondary);
                        text-decoration: none;
                    }

                    & a:hover {
                        color: var(--el-color-primary);
                        cursor: pointer;
                    }
                }
            }
        }
    }

    .personal-recommend-row {
        .personal-recommend-col {
            .personal-recommend {
                position: relative;
                height: 100px;
                border-radius: 3px;
                overflow: hidden;
                cursor: pointer;

                &:hover {
                    i {
                        right: 0px;
                        bottom: 0px;
                        transition: all ease 0.3s;
                    }
                }

                i {
                    position: absolute;
                    right: -10px;
                    bottom: -10px;
                    font-size: 70px;
                    transform: rotate(-30deg);
                    transition: all ease 0.3s;
                }

                .personal-recommend-auto {
                    padding: 15px;
                    position: absolute;
                    left: 0;
                    top: 5%;
                    color: var(--next-color-white);

                    .personal-recommend-msg {
                        font-size: 12px;
                        margin-top: 10px;
                    }
                }
            }
        }
    }

    .personal-edit {
        .personal-edit-title {
            position: relative;
            padding-left: 10px;
            color: var(--el-text-color-regular);

            &::after {
                content: '';
                width: 2px;
                height: 10px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translateY(-50%);
                background: var(--el-color-primary);
            }
        }

        .personal-edit-safe-box {
            border-bottom: 1px solid var(--el-border-color-light, #ebeef5);
            padding: 15px 0;

            .personal-edit-safe-item {
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: space-between;

                .personal-edit-safe-item-left {
                    flex: 1;
                    overflow: hidden;

                    .personal-edit-safe-item-left-label {
                        color: var(--el-text-color-regular);
                        margin-bottom: 5px;
                    }

                    .personal-edit-safe-item-left-value {
                        color: var(--el-text-color-secondary);
                        @include text-ellipsis(1);
                        margin-right: 15px;
                    }
                }
            }

            &:last-of-type {
                padding-bottom: 0;
                border-bottom: none;
            }
        }
    }
}
</style>
  